import { Toast } from "vant";
export default {
  components: {},
  props: {},
  data() {
    return {
      uploadUrl: "upload.uploadPic", //上传图片
      orderId: "",
      imgUrl: "", //授权信息图片
      idcardFront: "", //身份证正面
      idcardBack: "", //身份证反面
      email: "", //邮箱
      isShiming: false, //是否实名 false未实名
      uploadShow: false //上传图片弹窗
    };
  },
  activated() {
    this.uploadUrl = this.fun.getRealUrl("upload.uploadPic", {});
    console.log(this.$route.params.id, "kkkkkkkkkk");
    this.orderId = this.$route.params.id;
    this.imgUrl = this.$route.params.pingzheng;
    this.checkShiming();
  },

  methods: {
   
    downFile() {
      window.open("https://shops.cg500.com/static/weituoshu.docx");
      // https://shops.cg500.com/static/upload/
    },
    openUploadPop() {
      this.uploadShow = true;
    },
    checkShiming() {
      // 图文化--是否实名
      var that = this;
      $http
        .get(
          "TuWenhua.is_shiming",
          {
            uid: localStorage.getItem("uid") ? localStorage.getItem("uid") : localStorage.getItem("mid")
          },
          "..."
        )
        .then(response => {
          console.log(response, "response is_shiming");
          that.idcardFront = response.data.idcard_a; //身份证正面
          that.idcardBack = response.data.idcard_b; //身份证反面
          that.email = response.data.email; //邮箱
          if (response.data.realname == "") {
            that.isShiming = false;
            // Toast("必须实名认证");
            // setTimeout(() => {
            //   this.$router.push(this.fun.getUrl("realAuth", { type: 2 }));
            // }, 1000);
          } else {
            that.isShiming = true;
          }
        });
    },
    uploadFile() {
      Toast("必须实名认证");
      setTimeout(() => {
        this.$router.push(this.fun.getUrl("realAuth", { type: 2, orderId: this.orderId }));
      }, 1000);
    },
    submit() {
      var That = this;
      if (this.imgUrl == "") {
        return this.$toast("授权信息不能为空");
      }
      if (this.email == "") {
        return this.$toast("邮箱不能为空");
      }
      var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

      if (!re.test(this.email)) {
        return this.$toast("请输入正确的邮箱");
      }
      if (this.idcardFront == "") {
        return this.$toast("身份证正面照不能为空");
      }
      if (this.idcardBack == "") {
        return this.$toast("身份证背面照不能为空");
      }
      //  上传订单凭证
      $http
        .post("TuWenhua.pingzheng", {
          order_id: That.orderId,
          url: That.imgUrl,
          email: That.email,
          idcard_a: That.idcardFront,
          idcard_b: That.idcardBack,
          uid: localStorage.getItem("uid") ? localStorage.getItem("uid") : localStorage.getItem("mid")
        })
        .then(res => {
          if (res.result == 0) {
            return this.$toast(res.msg);
          }
          this.$toast("上传成功");
          this.uploadShow = false;
          this.$router.push(this.fun.getUrl("orderlist", { status: "2" }));
        });
    },
    /*vant图片上传*/
    onRead(e, flag) {
      console.log(flag.name, "e, flag");
      let typeUpload = flag.name; //0 授权信息 1身份证正面 2身份证反面
      Toast.loading({
        message: "上传中",
        forbidClick: true
      });
      this.stopButton = true;
      let fd = new FormData();

      if (flag === true) {
        fd.append("file", e); // 第一个参数字符串可以填任意命名，第二个根据对象属性来找到file
      } else {
        fd.append("file", e.file); // 第一个参数字符串可以填任意命名，第二个根据对象属性来找到file
      }
      var That = this;
      axios
        .post(this.uploadUrl, fd, {
          headers: { "Content-Type": "multipart/form-data" }
        })
        .then(response => {
          var responseData = response.data;
          console.log(responseData, "responseData");
          if (responseData.result === 1) {
            Toast.clear();
            if (typeUpload == 0) {
              That.imgUrl = responseData.data.img_url;
            } else if (typeUpload == 1) {
              That.idcardFront = responseData.data.img_url; //身份证正面
            } else if (typeUpload == 2) {
              That.idcardBack = responseData.data.img_url; //身份证反面
            }
            // 上传订单凭证
            // $http
            //   .post("TuWenhua.pingzheng", {
            //     order_id: That.orderId,
            //     url: That.imgUrl
            //   })
            //   .then(res => {
            //     if (res.result == 0) {
            //       return this.$toast(res.msg);
            //     }
            //     this.$toast("上传成功");
            //     this.$router.push(this.fun.getUrl("orderlist", { status: "2" }));
            //   });
          } else {
            Toast(responseData.msg);
          }
        })
        .catch(error => {
          console.log(error);
        });
    }
  }
};
